package proxy;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;

/**
 * Created by zhongwei on 2017/1/9.
 */
public class Proxy {

    static HttpClient client = HttpClients.createDefault();

    public static String getProxy() throws IOException {
        HttpResponse response = client.execute(new HttpGet("http://202.114.70.53:5454/"));
        String content = EntityUtils.toString(response.getEntity());
        EntityUtils.consumeQuietly(response.getEntity());
        JSONObject json = (JSONObject) JSON.parse(content);
        JSONArray array = (JSONArray) json.get("proxies");
        String proxy = (String) array.get(0);
        proxy = proxy.replaceAll("http://", "");
        return proxy;
    }

    public static void main(String[] args) throws IOException {
        System.out.println(getProxy());
    }
}
